package com.xiaoxin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.lease.model.entity.ApartmentLabel;
import com.xiaoxin.lease.model.entity.LabelInfo;
import com.xiaoxin.lease.model.enums.ItemType;
import com.xiaoxin.lease.web.admin.mapper.ApartmentLabelMapper;
import com.xiaoxin.lease.web.admin.service.ApartmentLabelService;
import com.xiaoxin.lease.web.admin.service.LabelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_label(公寓标签关联表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class ApartmentLabelServiceImpl extends ServiceImpl<ApartmentLabelMapper, ApartmentLabel>
        implements ApartmentLabelService {

    @Autowired
    private LabelInfoService labelInfoService;

    @Override
    public List<LabelInfo> selectLabelByApartmentId(Long apartmentId) {
        List<ApartmentLabel> apartmentLabels = super.list(new LambdaQueryWrapper<ApartmentLabel>().eq(ApartmentLabel::getApartmentId, apartmentId));
        List<LabelInfo> labelInfoList = labelInfoService.list(new LambdaQueryWrapper<LabelInfo>().eq(LabelInfo::getType, ItemType.APARTMENT).in(LabelInfo::getId, apartmentLabels.stream().map(f -> f.getLabelId()).toList()));
        return labelInfoList;
    }

}




